﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using TarreOA.TarreOAModels;
namespace TarreOA.TarreOADAL
{
    public class EditFormNameDAO
    {
        public Boolean updateFormName(string id,string name)
        {
            SqlConnection conn = null;
            bool state = false;
            try
            {
                conn = SQLManager.GetConn();
                conn.Open();
                SqlCommand cmd = new SqlCommand("update flow_forms set form_name=@fname where id=@id", conn);
                cmd.Parameters.Add(new SqlParameter("@fname", name));
                cmd.Parameters.Add(new SqlParameter("@id", id));
                if (cmd.ExecuteNonQuery() == 1)
                {
                    state = true;
                }
                conn.Close();
                conn.Dispose();

                state = true;
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
            }
            finally {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }
            return state;
        }
        public string getFormName(string id) {
            SqlConnection conn = null;
            SqlDataReader dr = null;
            String detail = "您访问的内容不存在或已被删除";
            try
            {
                conn = SQLManager.GetConn();
                conn.Open();

                SqlCommand cmd = new SqlCommand("select form_name from flow_forms where id= @id", conn);
                cmd.Parameters.Add(new SqlParameter("@id", id));
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    detail = (String)dr["form_name"];

                }
                dr.Close();
                conn.Close();
                dr.Dispose();
                conn.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }
            return detail;
        }
    }
}
